/**
 * Copyright(c): 2018 com.mjduan All rights reserved.
 * 项目名：springboot-websocket
 * 注意：未经作者允许，不得外传
 */
package com.mjduan.project.springbootwebsocket;


import java.io.IOException;

import io.netty.handler.codec.http.HttpHeaders;

import org.yeauty.annotation.OnClose;
import org.yeauty.annotation.OnError;
import org.yeauty.annotation.OnMessage;
import org.yeauty.annotation.OnOpen;
import org.yeauty.annotation.ServerEndpoint;
import org.yeauty.pojo.Session;

import org.springframework.stereotype.Component;

/**
 * @see <a href="https://my.oschina.net/u/3580577/blog/2088114?from=20180923">看这篇oschina的博客</a>
 *
 * @author dmj1161859184@126.com 2018-09-24 12:13
 * @version 1.0
 * @since 1.0
 */
@ServerEndpoint
@Component
public class MyWebSocket {

    @OnOpen
    public void onOpen(Session session, HttpHeaders headers) {
        System.out.println("new Connection");
    }

    @OnClose
    public void onClose(Session session) throws IOException {
        System.out.println("one connection closed");
    }

    @OnError
    public void onError(Session session, Throwable throwable) {
        throwable.printStackTrace();
    }

    @OnMessage
    public void OnMessage(Session session, String message) {
        System.out.println(message);
        session.sendText("Hello Netty!");
    }
}
